<template>
    <div class="programme px-20">
        <div v-if="isOpen" class="pt-15">
            <form-view
                :list="formMember"
                :gridFormItem="4"
                :height="0"
                row
            ></form-view>
        </div>
        <div class="fr-ac-jsb pb-15" :class="isOpen ? '' : 'pt-15'">
            <p></p>
            <el-button @click="isOpen = !isOpen">
                <el-icon>
                    <Search />
                </el-icon>
            </el-button>
        </div>
        <table-view
            :data="tableData"
            :propList="tableProp"
            :total="tableTotal"
            :pageSize="15"
            @pageClick="tablePage"
            :spacing="20"
        ></table-view>
        <dialog-view
            :dialog="programmeLOG"
            @close="close"
            width="60%"
            title="录取日志"
            :spacing="8"
            :background="accountdelBG"
        >
            <template #main>
                <div class="px-20 py-10">
                    <table-view
                        :data="tableLogData"
                        :propList="tableLogProp"
                        :total="tableLogTotal"
                        :spacing="20"
                        :pageSize="logSize"
                        paging="center"
                        layout="prev, pager, next ,total,jumper"
                        jumper
                        stripe
                        border
                        @pageClick="tableLogPage"
                        @jumperClick="tableLogSize"
                    ></table-view>
                </div>
            </template>
        </dialog-view>
    </div>
</template>
<script setup>
import { onMounted, ref } from "vue";
import {
    overviewList,
    overviewExportLog,
    submitExport,
    checkExport_fj,
    checkExport_zj,
    completeExport_fj,
    completeExport_zj,
} from "./volunteer";
import { useUserStore } from "@/store/userStore";
import { red, blue, purple, purpleWhite } from "@/comment/data";
import {
    updateMessage,
    updateOrGetValue,
    optionsArray,
    flieDownload,
} from "@/comment/method";
import { zxkm, sxkm, sex, year, getYear } from "./data";
const userStore = useUserStore();
const options = ref([
    {
        id: 1,
        label: "意向信息",
        isPopover: false,
        tooltip: "",
        style: purple,
        void: async (val) => {
            const res = await submitExport({
                custom_id: val.id,
            });
            let name = `信息核对(ID${val.id}:${val.ksxx_name})`;
            flieDownload(res, name, "docx");
        },
    },
    {
        id: 2,
        label: "审核方案表",
        isPopover: false,
        tooltip: "",
        style: purple,
        void: async (val) => {
            switch (userStore.user.province) {
                case "福建":
                    const res1 = await checkExport_fj({
                        volunteer_id: val.volunteer_id,
                    });
                    let name1 = `志愿表(ID${val.id}:${val.ksxx_name})`;
                    flieDownload(res1, name1, "xlsx");
                    break;
                case "浙江":
                    const res2 = await checkExport_zj({
                        volunteer_id: val.volunteer_id,
                    });
                    let name2 = `志愿表(ID${val.id}:${val.ksxx_name})`;
                    flieDownload(res2, name2, "xlsx");
                    break;
            }
        },
    },
    {
        id: 3,
        label: "导出方案表",
        isPopover: false,
        tooltip: "",
        style: purple,
        void: async (val) => {
            switch (userStore.user.province) {
                case "福建":
                    const res1 = await completeExport_fj({
                        volunteer_id: val.volunteer_id,
                    });
                    let name1 = `志愿表(ID${val.id}:${val.ksxx_name})`;
                    flieDownload(res1, name1, "xlsx");
                    break;
                case "浙江":
                    const res2 = await completeExport_zj({
                        volunteer_id: val.volunteer_id,
                    });
                    let name2 = `志愿表(ID${val.id}:${val.ksxx_name})`;
                    flieDownload(res2, name2, "xlsx");
                    break;
            }
        },
    },
    {
        id: 4,
        label: "点击生成PDF",
        isPopover: false,
        tooltip: "",
        style: purple,
        void: (val) => {
            if (val.completion_pdf_status === 1) {
                updateMessage("PDF正在生成中", "warning");
            }
        },
    },
]);
const tableData = ref([]);
const tableProp = ref([
    {
        id: 1,
        prop: "id",
        label: "ID",
    },
    {
        id: 2,
        prop: "phone",
        label: "手机号",
    },
    {
        id: 3,
        prop: "year",
        label: "年份",
    },
    {
        id: 4,
        prop: "ksxx_name",
        label: "考生姓名",
    },
    {
        id: 5,
        prop: "xk",
        label: "选科",
    },
    {
        id: 6,
        prop: "score",
        label: "分数",
    },
    {
        id: 7,
        prop: "ksxx_sex",
        label: "考生性别",
    },
    {
        id: 8,
        prop: "value_ranking",
        label: "价值排序",
    },
    {
        id: 9,
        prop: "remark",
        label: "备注",
    },
    {
        id: 10,
        prop: "",
        label: "操作",
        operate: options.value,
    },
]);
const tableTotal = ref(0);
const tableInfo = ref({});
const programmeCondition = ref({
    ksxx_name: "",
    phone: "",
    ksxx_sxkm: "",
    ksxx_zxkm: "",
    min_score: "",
    max_score: "",
    ksxx_sex: "",
    remark: "",
    year: getYear,
});
const isOpen = ref(false);
const programmeLOG = ref(false);
const accountdelBG = ref(
    "url(https://file.gkzzd.cn/www/gkzzd/uploads/20250625/d8fb87ce99e397e759bde7c949029956.jpg) no-repeat"
);
const tableLogData = ref([]);
const tableLogProp = ref([
    {
        id: 1,
        prop: "id",
        label: "ID",
    },
    {
        id: 2,
        prop: "title",
        label: "操作类型",
    },
    {
        id: 3,
        prop: "file_type",
        label: "文件类型",
    },
    {
        id: 4,
        prop: "createtime",
        label: "时间",
    },
    {
        id: 5,
        prop: "nickname",
        label: "操作人员",
    },
    {
        id: 6,
        prop: "",
        label: "操作",
        operate: [
            {
                id: 1,
                label: "下载",
                isPopover: false,
                tooltip: "",
                style: purple,
                void: (val) => {
                    let name = `${val.title}(ID${val.id})`;
                    switch (val.file_type) {
                        case "word":
                            flieDownload(val.content, name, "docx");
                            break;
                        case "excel":
                            flieDownload(val.content, name, "xlsx");
                            break;
                        case "pdf":
                            const a = document.createElement("a");
                            a.href =
                                import.meta.env.VITE_API_URL +
                                "/api/recommendation/fujian_01/complete/download_pdf?url=" +
                                val.content +
                                "&name=ID_" +
                                val.id;
                            a.target = "_blank";
                            a.click();
                            break;
                    }
                },
            },
        ],
    },
]);
const tableLogTotal = ref(0);
const logSize = ref(15);
const formMember = ref([
    {
        id: 1,
        prefix: false,
        type: "",
        label: "姓名",
        model: "",
        prop: "ksxx_name",
        suffixIcon: "",
        rules: [],
        formType: "input",
        placeholder: "请输入姓名",
        list: [],
    },
    {
        id: 2,
        prefix: false,
        type: "",
        label: "手机号",
        model: "",
        prop: "phone",
        suffixIcon: "",
        rules: [],
        formType: "input",
        placeholder: "请输入手机号",
        list: [],
    },
    {
        id: 3,
        prefix: false,
        type: "",
        label: "性别",
        model: "",
        prop: "ksxx_sex",
        suffixIcon: "CaretBottom",
        rules: [],
        formType: "select",
        placeholder: "请选择",
        list: optionsArray(sex, "", "", "请选择"),
    },
    {
        id: 4,
        prefix: false,
        type: "",
        label: "首选",
        model: "",
        prop: "ksxx_sxkm",
        suffixIcon: "CaretBottom",
        rules: [],
        formType: "select",
        placeholder: "请选择",
        list: optionsArray(sxkm, "", "", "请选择"),
    },
    {
        id: 5,
        prefix: false,
        type: "",
        label: "再选",
        model: "",
        prop: "ksxx_zxkm",
        suffixIcon: "CaretBottom",
        rules: [],
        formType: "select",
        placeholder: "请选择",
        list: optionsArray(zxkm, "", "", "请选择"),
    },
    {
        id: 6,
        prefix: false,
        type: "",
        label: "分数",
        model: "",
        prop: "score",
        suffixIcon: "",
        rules: [],
        formType: "col",
        placeholder: "请选择",
        list: [],
    },
    {
        id: 9,
        prefix: false,
        type: "",
        label: "备注",
        model: "",
        prop: "remark",
        suffixIcon: "",
        rules: [],
        formType: "input",
        placeholder: "请输入备注",
        list: [],
    },
    {
        id: 7,
        prefix: false,
        type: "",
        label: "年份",
        model: getYear,
        prop: "year",
        suffixIcon: "CaretBottom",
        rules: [],
        formType: "select",
        placeholder: "请选择",
        list: optionsArray(year),
    },
    {
        id: 8,
        prefix: false,
        type: "",
        label: "",
        model: "",
        prop: "",
        suffixIcon: "",
        rules: [],
        formType: "null",
        placeholder: "",
        list: [
            {
                label: "查询",
                value: "查询",
                type: "query",
                style: purple,
                void: (val) => {
                    let operate;
                    if (val.year == 2024) {
                        operate = [
                            {
                                id: 1,
                                label: "导出日志",
                                isPopover: false,
                                tooltip: "",
                                style: purple,
                                void: (val) => {
                                    programmeLOG.value = true;
                                    tableInfo.value = val;
                                    log(val.id);
                                },
                            },
                        ];
                    } else {
                        operate = options.value;
                    }
                    updateOrGetValue(10, "operate", tableProp.value, operate);
                    list(val);
                },
            },
            {
                label: "重置",
                value: "重置",
                type: "reset",
                style: purpleWhite,
                void: (val) => {
                    updateOrGetValue(
                        10,
                        "operate",
                        tableProp.value,
                        options.value
                    );
                    list(val);
                },
            },
        ],
    },
]);
const list = async (condition, page = 1) => {
    let data = {
        ...condition,
        limit: 15,
        page: page,
        province: userStore.user.province,
    };
    const res = await overviewList(data);
    let list = res.lists.map((item) => {
        return {
            ...item,
            remark: `备注：${item.remark ? item.remark : "暂无备注"}`,
        };
    });
    tableData.value = list;
    tableTotal.value = res.total;
};
const tablePage = (val) => {
    list(programmeCondition.value, val);
};
const log = async (id, page = 1, limit = 15) => {
    const res = await overviewExportLog({
        limit: limit,
        page: page,
        custom_id: id,
    });
    tableLogData.value = res.lists;
    tableLogTotal.value = res.total;
};
const tableLogPage = (val) => {
    log(tableInfo.value.id, val);
};
const tableLogSize = (val) => {
    logSize.value = val;
    log(tableInfo.value.id, 1, val);
};
const close = () => {
    programmeLOG.value = false;
};
onMounted(() => {
    list(programmeCondition.value);
});
</script>
<style lang="scss" scoped>
</style>
